var t = require;
var e = module;
var o = exports;
Object.defineProperty(o, "__esModule", {value: !0});
var a,
    i,
    n = t("UIManager"),
    r = t("UIConfig");
(function (t) {
    t[(t.None = 0)] = "None";
    t[(t.inRecord = 1)] = "inRecord";
    t[(t.isPause = 3)] = "isPause";
    t[(t.recordDone = 4)] = "recordDone";
})(a || (a = {}));
(function (t) {
    t.onStart = "onStart";
    t.onPause = "onPause";
    t.onResume = "onResume";
    t.onStop = "onStop";
    t.onClear = "onClear";
    t.onError = "onError";
    t.onShareVideoEnd = "onShareVideoEnd";
    t.onClipVideoEnd = "onClipVideoEnd";
})(i || (i = {}));
var s = new ((function () {
    function t() {
        this.curRecordStatus = a.None;
        this.recordManager = null;
        this.sharePath = "";
        this.timeMinLimite = 3e3;
        this.remberStartTime = 0;
        this.addUpdataCallback = [];
        this.isShare = !1;
        this.canShareRewardTime = 5;
        this.curRecordTime = 1;
        this.shareRewardDiamond = 10;
        this.isGetReward = !1;
        this.timeMaxLimite = 30;
    }
    t.prototype.addUpdataCallBack = function (t) {
        this.addUpdataCallback.push(t);
    };
    t.prototype.clearUpdataCallBack = function () {
        this.addUpdataCallback.length = 0;
    };
    t.prototype.doUpadatCallback = function () {
        for (var t = 0; t < this.addUpdataCallback.length; t++) this.addUpdataCallback[t]();
    };
    t.prototype.clickRecord = function (t, e) {
        this.curRecordStatus == a.None ? this.start(t, e) : this.curRecordStatus == a.inRecord && this.stop(t, e);
    };
    t.prototype.getBtnStr = function () {
        var t = "";
        switch (this.curRecordStatus) {
            case a.None:
                t = "";
                break;
            case a.inRecord:
                t = this.getFormat(Math.floor((Date.now() - this.remberStartTime) / 1e3));
                break;
            case a.recordDone:
                t = "";
        }
        return t;
    };
    t.prototype.getProNum = function () {
        var t = 0;
        switch (this.curRecordStatus) {
            case a.None:
                break;
            case a.inRecord:
                t = (Date.now() - this.remberStartTime) / (1e3 * this.timeMaxLimite);
                break;
            case a.recordDone:
        }
        return t;
    };
    t.prototype.isRecord = function () {
        return this.curRecordStatus == a.inRecord;
    };
    t.prototype.getFormat = function (t) {
        return this.getFont(Math.floor(t / 60)) + ":" + this.getFont(t % 60);
    };
    t.prototype.getFont = function (t) {
        return 0 == t ? "00" : 1 == (t + "").length ? "0" + t : t + "";
    };
    t.prototype.canStartRecord = function () {
        return this.curRecordStatus == a.None;
    };
    t.prototype.start = function (t, e) {
        var o = this;
        if (this.canStartRecord()) {
            this.checkRecord();
            if (this.recordManager) {
                this.startSuccessCallBack = t;
                this.sharePath = "";
                var a = this.recordManager;
                console.log("开始录屏");
                this.isGetReward = !1;
                n.default.open(r.UIID.UIToast, {msg: "开始录制"});
                setTimeout(function () {
                    console.log("显示完开始录屏，再开始录屏");
                    a.start({duration: o.timeMaxLimite, isMarkOpen: !0});
                }, 2500);
            }
        } else e && e();
    };
    t.prototype.isMinTime = function () {
        return Date.now() - this.remberStartTime < this.timeMinLimite;
    };
    t.prototype.checkRecord = function () {
        var t = this;
        if (!this.recordManager && this.Plat && this.Plat.getGameRecorderManager) {
            console.log("初始化录屏");
            this.recordManager = this.Plat.getGameRecorderManager();
            this.recordManager.onStart(function () {
                console.log("录屏onStart");
                t.remberStartTime = Date.now();
                t.curRecordStatus = a.inRecord;
                t.startSuccessCallBack && t.startSuccessCallBack();
                t.doUpadatCallback();
            });
            this.recordManager.onStop(function (e) {
                console.log("录屏onStop");
                t.curRecordStatus = a.recordDone;
                t.sharePath = e.videoPath;
                t.stopSuccessCallBack && t.stopSuccessCallBack();
                t.doUpadatCallback();
            });
        }
    };
    t.prototype.stop = function (t, e) {
        if ((this.curRecordStatus == a.inRecord || a.isPause) && this.recordManager) {
            var o = this.recordManager;
            this.stopSuccessCallBack = t;
            o.stop();
            if (this.isMinTime()) {
                this.curRecordStatus = a.None;
                e && e();
            }
        }
    };
    t.prototype.clear = function () {
        this.curRecordStatus = a.None;
        this.sharePath = "";
        this.startSuccessCallBack = null;
        this.stopSuccessCallBack = null;
    };
    t.prototype.share = function (t, e) {
        if (this.canShareVideo()) {
            var o = {
                channel: "video",
                title: "猫咪餐厅",
                desc: "#猫咪餐厅#治愈系宝藏游戏推荐#解压小游戏",
                success: function () {
                    t && t();
                    console.log("RecordVideoManager ----------------- 分享成功");
                },
                fail: function (t) {
                    e && e();
                    console.log("RecordVideoManager ----------------- 分享失败", t);
                }
            };
            o.extra = {videoPath: this.sharePath, videoTopics: ["猫咪餐厅", "治愈系宝藏游戏推荐", "解压小游戏"]};
            this.Plat.shareAppMessage(o);
        }
    };
    t.prototype.canShareVideo = function () {
        return this.curRecordStatus == a.recordDone && "" != this.sharePath;
    };
    Object.defineProperty(t.prototype, "Plat", {
        get: function () {
            return window.tt;
        },
        enumerable: !1,
        configurable: !0
    });
    t.prototype.reloadRecordStatus = function () {
        this.curRecordStatus = a.None;
        console.log("当前的状态是", this.curRecordStatus);
        console.log(this.getBtnStr());
    };
    t.prototype.setStopSuccessCallBack = function (t) {
        this.stopSuccessCallBack = t;
    };
    t.prototype.setShareEndSuccessCallBack = function (t, e) {
        this.shareEndSuccessCallBack = t;
        this.shareEndFailCallBack = e;
    };
    return t;
})())();
window.RecordVideoManager = s;
o.default = s;
